<style lang="scss" scoped="">
  @import '../../styles/variables';

</style>
<template>
  <div class="page-main">
    <div class="list-bar-tools">
      <div class="flex">
        <el-input placeholder="" v-model="filter.nodeName" class="list-bar-tools-input" size="mini" clearable="">
          <template slot="prepend">节点名称</template>
        </el-input>
        <el-date-picker
          v-model="dates"
          type="daterange"
          align="right"
          unlink-panels
          size="mini"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          style="width:420px;margin:0 10px;"
          value-format="yyyy-MM-dd"
          @change="datePicked"
        >
        </el-date-picker>

        <el-button size="mini" type="primary" plain="" icon="el-icon-search"></el-button>

      </div>
    </div>
    <el-table
      :data="nodeList"
      border
      style="width: 100%">
      <el-table-column
        prop="nodeName"
        label="节点名称">
      </el-table-column>
      <el-table-column
        prop="fromNodeName"
        label="操作来源">
      </el-table-column>
      <el-table-column
        prop="time"
        label="时间">
      </el-table-column>
      <el-table-column
        prop="status"
        label="类型">
      </el-table-column>

    </el-table>

    <div class="pagination">
      <el-pagination
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="1"
        :page-sizes="[10, 50, 100]"
        :page-size="filter.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="nodeCount">
      </el-pagination>
    </div>

  </div>
</template>
<script>
  import utils from '@/utils/utils';
  import {nodeService} from '@/api/index';
  import {mapGetters} from 'vuex';

  export default {
    data() {
      return {
        filter: {
          pageNo: 1,
          pageSize: 10,
          start: 0,
          nodeName: '',
          status: '',
          startTime: '',
          endTime: ''
        },
        nodeCount: 0,
        nodeList: [],
        dates: ''
      };
    },
    computed: {},
    watch: {
      'filter': {
        handler: function () {
          this.getNodeList();
        },
        deep: true,
        immediate: true
      }
    },
    components: {},
    methods: {
      handleCurrentChange(currentPageNo) {
        this.filter.start = (currentPageNo - 1) * this.filter.pageSize;
      },
      handleSizeChange(pageSize) {
        this.filter.pageSize = pageSize;
        localStorage.setItem('node-opera-page-size', pageSize);

      },
      getNodeList() {
        nodeService.getNodesOperatorInfoPage(this.filter).then(res => {
          this.nodeCount = res.data.total;
          this.nodeList = res.data.rows;
        });
      },
      datePicked(dateItem) {
        this.filter = Object.assign(this.filter, {
          start: 0,
          startTime: dateItem[0],
          endTime: dateItem[1]
        });
      }
    },
    created() {
      let oldPageSize = localStorage.getItem('node-opera-page-size');
      if (!oldPageSize) {
        oldPageSize = 10;
      }
      this.filter.pageSize = Math.floor(oldPageSize);
    },
    mounted() {
    }
  };
</script>
